package cn.tedu.ivos01.vehicle.controller;

import cn.tedu.ivos01.base.response.JsonResult;
import cn.tedu.ivos01.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos01.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos01.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos01.vehicle.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api(tags = "车辆模块")
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    private VehicleService  vehicleService;

    @ApiOperation("查询车辆信息接口")
    @GetMapping("/select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery){
        log.debug("查询车辆: vehicleQuery={}",vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation("保存车辆信息")
    @PostMapping("/save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam){
        log.debug("保存车辆参数: vehicleSaveParam: {}",vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.debug("删除车辆信息参数: id ={}",id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

}
